package com.qiyi.player.wonder.plugins.setting.view
{
   import com.iqiyi.components.panelSystem.impls.BasePanel;
   import com.qiyi.player.wonder.common.status.Status;
   import com.qiyi.player.wonder.common.vo.UserInfoVO;
   import common.CommonCloseBtn;
   import common.CommonBg;
   import flash.text.TextField;
   import scenetile.MalePng;
   import scenetile.FemalePng;
   import offinewatch.OffineDownloadlBtn;
   import flash.display.Shape;
   import flash.display.Loader;
   import flash.display.DisplayObjectContainer;
   import com.qiyi.player.wonder.common.ui.FastCreator;
   import flash.events.TextEvent;
   import flash.events.MouseEvent;
   import com.qiyi.player.user.UserDef;
   import gs.TweenLite;
   import com.qiyi.player.wonder.plugins.setting.SettingDef;
   import com.iqiyi.components.global.GlobalStage;
   import com.qiyi.player.wonder.body.BodyDef;
   import flash.display.MovieClip;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import flash.net.URLRequest;
   import com.qiyi.player.wonder.common.config.SystemConfig;
   import flash.system.LoaderContext;
   
   public class FilterView extends BasePanel
   {
      
      public function FilterView(param1:DisplayObjectContainer, param2:Status, param3:UserInfoVO) {
         super(NAME,param1);
         this._container = param1;
         this._status = param2;
         this._userInfoVO = param3;
         type = BodyDef.VIEW_TYPE_POPUP;
         this.initUI();
      }
      
      public static const NAME:String = "com.qiyi.player.wonder.plugins.setting.view.FilterView";
      
      private static const TEXT_CONFIRM:String = "确定";
      
      private static const TF_TIME:String = "播放时间缩短为";
      
      private static const TF_PUBLIC_TITLE:String = "开启绿镜模式，为您播放最精彩的<font color=\'#f05b26\'>橙色</font>部分";
      
      private static const TF_MALE_TITLE_OPEN_MALE:String = "帅哥，为您开启<font color=\'#699f00\'>男生版绿镜</font>模式，" + "只播放<font color=\'#f05b26\'>橙色部分</font>";
      
      private static const TF_MALE_TITLE_OPEN_COMMON:String = "帅哥，为您开启<font color=\'#699f00\'>大众版绿镜</font>模式，" + "只播放<font color=\'#f05b26\'>橙色部分</font>";
      
      private static const TF_MALE_FAULT_HAS_FEMALE:String = "您还可以看看" + "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>绿镜女生版</font></a>";
      
      private static const TF_MALE_FAULT_HAS_PUBLIC:String = "您还可以看看" + "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>绿镜大众版</font></a>";
      
      private static const TF_FEMALE_TITLE_OPEN_FEMALE:String = "美女，为您开启<font color=\'#699f00\'>女生版绿镜</font>模式，" + "只播放<font color=\'#f05b26\'>橙色部分</font>";
      
      private static const TF_FEMALE_TITLE_OPEN_COMMON:String = "美女，为您开启<font color=\'#699f00\'>大众版绿镜</font>模式，" + "只播放<font color=\'#f05b26\'>橙色部分</font>";
      
      private static const TF_FEMALE_FAULT_HAS_MALE:String = "您还可以看看" + "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>绿镜男生版</font></a>";
      
      private static const TF_FEMALE_FAULT_HAS_PUBLIC:String = "您还可以看看" + "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>绿镜大众版</font></a>";
      
      private static const TF_MALE_GUESS_FAULT_TITLE_MALE:String = "帅哥，刚刚的男生版好看么？";
      
      private static const TF_MALE_GUESS_FAULT_TITLE_FEMALE:String = "帅哥，刚刚的女生版好看么？";
      
      private static const TF_MALE_GUESS_FAULT_TITLE_COMMON:String = "帅哥，刚刚的大众版好看么？";
      
      private static const TF_MALE_GUESS_FAULT_LINK:String = "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>" + "你错了！我是美女</font></a>";
      
      private static const TF_FEMALE_GUESS_FAULT_TITLE_MALE:String = "美女，刚刚的男生版好看么？";
      
      private static const TF_FEMALE_GUESS_FAULT_TITLE_FEMALE:String = "美女，刚刚的女生版好看么？";
      
      private static const TF_FEMALE_GUESS_FAULT_TITLE_COMMON:String = "美女，刚刚的大众版好看么？";
      
      private static const TF_FEMALE_GUESS_FAULT_LINK:String = "<a href=\'event:onTextEventClick\'><font color=\'#699f00\'>" + "你错了！我是帅哥</font></a>";
      
      private var _status:Status;
      
      private var _userInfoVO:UserInfoVO;
      
      private var _closeBtn:CommonCloseBtn;
      
      private var _bg:CommonBg;
      
      private var _title:TextField;
      
      private var _explainTime:TextField;
      
      private var _time:TextField;
      
      private var _guessFault:TextField;
      
      private var _malePng:MalePng;
      
      private var _femalePng:FemalePng;
      
      private var _confirmBtn:OffineDownloadlBtn;
      
      private var _contirmTF:TextField;
      
      private var _bgShape:Shape;
      
      private var _filterMovieClip:Loader;
      
      private var _container:DisplayObjectContainer;
      
      private var _sexType:uint = 0;
      
      private var _curSexType:uint = 0;
      
      private var _isHavAtherData:Boolean = false;
      
      public function get curSexType() : uint {
         return this._curSexType;
      }
      
      public function set curSexType(param1:uint) : void {
         this._curSexType = param1;
      }
      
      public function get isHavAtherData() : Boolean {
         return this._isHavAtherData;
      }
      
      public function set isHavAtherData(param1:Boolean) : void {
         this._isHavAtherData = param1;
      }
      
      public function get sexType() : uint {
         return this._sexType;
      }
      
      public function set sexType(param1:uint) : void {
         this._sexType = param1;
      }
      
      private function initUI() : void {
         this._bg = new CommonBg();
         this._bg.width = 400;
         addChild(this._bg);
         this._malePng = new MalePng();
         this._malePng.x = (this._bg.width - this._malePng.width) / 2;
         this._malePng.y = 10;
         addChild(this._malePng);
         this._femalePng = new FemalePng();
         this._femalePng.x = (this._bg.width - this._femalePng.width) / 2;
         this._femalePng.y = 10;
         addChild(this._femalePng);
         this._title = FastCreator.createLabel(TF_PUBLIC_TITLE,16777215,14);
         addChild(this._title);
         this._explainTime = FastCreator.createLabel(TF_TIME,16777215,14);
         addChild(this._explainTime);
         this._time = FastCreator.createLabel(TF_TIME,16777215,20);
         addChild(this._time);
         this._guessFault = FastCreator.createLabel(TF_TIME,16777215,14);
         addChild(this._guessFault);
         this._explainTime.mouseEnabled = this._explainTime.selectable = this._time.mouseEnabled = this._time.selectable = this._title.mouseEnabled = this._title.selectable = false;
         this._confirmBtn = new OffineDownloadlBtn();
         this._confirmBtn.x = (this._bg.width - this._confirmBtn.width) / 2;
         this._confirmBtn.y = 100;
         addChild(this._confirmBtn);
         this._contirmTF = FastCreator.createLabel(TEXT_CONFIRM,16777215,14);
         this._contirmTF.x = this._confirmBtn.x + (this._confirmBtn.width - this._contirmTF.width) / 2;
         this._contirmTF.y = this._confirmBtn.y + (this._confirmBtn.height - this._contirmTF.height) / 2;
         this._contirmTF.mouseEnabled = false;
         addChild(this._contirmTF);
         this._closeBtn = new CommonCloseBtn();
         this._closeBtn.x = this._bg.width - this._closeBtn.width - 5;
         this._closeBtn.y = 1;
         addChild(this._closeBtn);
         this._bgShape = new Shape();
         this._guessFault.addEventListener(TextEvent.LINK,this.onTextEventClick);
         this._closeBtn.addEventListener(MouseEvent.CLICK,this.onCloseBtnClick);
         this._confirmBtn.addEventListener(MouseEvent.CLICK,this.onCloseBtnClick);
      }
      
      public function setPanelTimeLeng(param1:uint) : void {
         this._time.text = param1 + "分钟";
      }
      
      public function initPublicPanel() : void {
         this._bg.height = 110;
         this._explainTime.visible = this._time.visible = true;
         this._femalePng.visible = this._malePng.visible = false;
         this._confirmBtn.visible = this._contirmTF.visible = false;
         this._title.htmlText = TF_PUBLIC_TITLE;
         this._title.x = (this._bg.width - this._title.textWidth) / 2;
         this._title.y = 24;
         this._explainTime.text = TF_TIME;
         this._explainTime.x = (this._bg.width - 68 - this._explainTime.textWidth) / 2;
         this._explainTime.y = 58;
         this._time.x = 230;
         this._time.y = 56;
         this._guessFault.x = this._guessFault.y = 0;
         this._guessFault.visible = false;
      }
      
      public function initGuessFaultPanel() : void {
         this._bg.height = 150;
         this._guessFault.visible = true;
         this._explainTime.visible = this._time.visible = false;
         this._femalePng.visible = this._malePng.visible = false;
         this._confirmBtn.visible = this._contirmTF.visible = true;
         this._title.htmlText = this.getGuessFaultPanelTitleString();
         this._title.x = (this._bg.width - this._title.textWidth) / 2;
         this._title.y = 24;
         this._guessFault.htmlText = this._sexType == UserDef.USER_SEX_MALE?TF_MALE_GUESS_FAULT_LINK:TF_FEMALE_GUESS_FAULT_LINK;
         this._guessFault.x = (this._bg.width - this._guessFault.textWidth) / 2;
         this._guessFault.y = 58;
      }
      
      public function initSexPanel() : void {
         this._bg.height = 210;
         this._explainTime.visible = this._time.visible = true;
         this._confirmBtn.visible = this._contirmTF.visible = false;
         var _loc1_:* = this._sexType == UserDef.USER_SEX_MALE;
         this._femalePng.visible = !_loc1_;
         this._malePng.visible = _loc1_;
         this._title.htmlText = this.getHasSexDataTitleString();
         this._title.x = (this._bg.width - this._title.textWidth) / 2;
         this._title.y = this._malePng.y + this._malePng.height;
         this._explainTime.x = (this._bg.width - 68 - this._explainTime.textWidth) / 2;
         this._explainTime.y = this._malePng.y + this._malePng.height + 30;
         this._time.x = 230;
         this._time.y = this._malePng.y + this._malePng.height + 28;
         this._guessFault.visible = true;
         this._guessFault.htmlText = this.getGuessFaultString();
         this._guessFault.x = (this._bg.width - this._guessFault.textWidth) / 2;
         this._guessFault.y = this._malePng.y + this._malePng.height + 58;
      }
      
      private function getGuessFaultPanelTitleString() : String {
         switch(this._curSexType)
         {
            case UserDef.USER_SEX_MALE:
               return this._sexType == UserDef.USER_SEX_MALE?TF_MALE_GUESS_FAULT_TITLE_MALE:TF_FEMALE_GUESS_FAULT_TITLE_MALE;
            case UserDef.USER_SEX_FEMALE:
               return this._sexType == UserDef.USER_SEX_MALE?TF_MALE_GUESS_FAULT_TITLE_FEMALE:TF_FEMALE_GUESS_FAULT_TITLE_FEMALE;
            default:
               return this._sexType == UserDef.USER_SEX_MALE?TF_MALE_GUESS_FAULT_TITLE_COMMON:TF_FEMALE_GUESS_FAULT_TITLE_COMMON;
         }
      }
      
      private function getHasSexDataTitleString() : String {
         if(this._sexType == UserDef.USER_SEX_MALE)
         {
            return this.curSexType == UserDef.USER_SEX_NONE?TF_MALE_TITLE_OPEN_COMMON:TF_MALE_TITLE_OPEN_MALE;
         }
         if(this._sexType == UserDef.USER_SEX_FEMALE)
         {
            return this.curSexType == UserDef.USER_SEX_NONE?TF_FEMALE_TITLE_OPEN_COMMON:TF_FEMALE_TITLE_OPEN_FEMALE;
         }
         return TF_PUBLIC_TITLE;
      }
      
      private function getGuessFaultString() : String {
         if(this._sexType == UserDef.USER_SEX_MALE)
         {
            return this._isHavAtherData?TF_MALE_FAULT_HAS_FEMALE:TF_MALE_FAULT_HAS_PUBLIC;
         }
         if(this._sexType == UserDef.USER_SEX_FEMALE)
         {
            return this._isHavAtherData?TF_FEMALE_FAULT_HAS_MALE:TF_FEMALE_FAULT_HAS_PUBLIC;
         }
         return "";
      }
      
      public function onAddStatus(param1:int) : void {
         this._status.addStatus(param1);
         switch(param1)
         {
            case SettingDef.STATUS_FILTER_OPEN:
               TweenLite.to(this._bg,5,{"onComplete":this.onCloseBtnClick});
               this.loaderMovieClip();
               this.open();
               break;
         }
      }
      
      public function onRemoveStatus(param1:int) : void {
         this._status.removeStatus(param1);
         switch(param1)
         {
            case SettingDef.STATUS_FILTER_OPEN:
               TweenLite.killTweensOf(this._bg);
               this.close();
               break;
         }
      }
      
      public function onUserInfoChanged(param1:UserInfoVO) : void {
         this._userInfoVO = param1;
      }
      
      override public function open(param1:DisplayObjectContainer = null) : void {
         if(!isOnStage)
         {
            super.open(param1);
            dispatchEvent(new SettingEvent(SettingEvent.Evt_FilterOpen));
         }
      }
      
      override public function close() : void {
         if(isOnStage)
         {
            super.close();
            dispatchEvent(new SettingEvent(SettingEvent.Evt_FilterClose));
         }
      }
      
      override protected function onAddToStage() : void {
         super.onAddToStage();
         this.onResize(GlobalStage.stage.stageWidth,GlobalStage.stage.stageHeight);
         alpha = 0;
         TweenLite.to(this,BodyDef.POPUP_TWEEN_TIME / 1000,{"alpha":1});
      }
      
      override protected function onRemoveFromStage() : void {
         super.onRemoveFromStage();
         TweenLite.killTweensOf(this);
      }
      
      public function onResize(param1:int, param2:int) : void {
         if(isOnStage)
         {
            x = (param1 - this._bg.width) / 2;
            y = (param2 - this._bg.height) / 2;
         }
      }
      
      public function playSkipMovieClip() : void {
         var _loc1_:MovieClip = null;
         if(this._filterMovieClip == null && this._filterMovieClip.content == null)
         {
            return;
         }
         this._filterMovieClip.scaleX = GlobalStage.stage.stageWidth / 980;
         this._filterMovieClip.scaleY = GlobalStage.stage.stageHeight / 480;
         if(!this._filterMovieClip.parent)
         {
            this._container.addChild(this._bgShape);
            this._container.addChild(this._filterMovieClip);
            _loc1_ = this._filterMovieClip.contentLoaderInfo.content as MovieClip;
            if(_loc1_)
            {
               _loc1_.filterMovieClip.gotoAndPlay(1);
            }
            this._bgShape.alpha = 1;
            this._bgShape.graphics.clear();
            this._bgShape.graphics.beginFill(0);
            this._bgShape.graphics.drawRect(0,0,GlobalStage.stage.stageWidth,GlobalStage.stage.stageHeight);
            this._bgShape.graphics.endFill();
            TweenLite.to(this._bgShape,2,
               {
                  "alpha":0,
                  "onComplete":this.onMCPlayComplete
               });
         }
      }
      
      private function onMCPlayComplete() : void {
         TweenLite.killTweensOf(this._bgShape);
         if(this._filterMovieClip.parent)
         {
            this._container.removeChild(this._filterMovieClip);
         }
         if(this._bgShape.parent)
         {
            this._container.removeChild(this._bgShape);
         }
      }
      
      private function loaderMovieClip() : void {
         if((this._filterMovieClip) && (this._filterMovieClip.content))
         {
            return;
         }
         this._filterMovieClip = new Loader();
         this._filterMovieClip.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onComplete);
         this._filterMovieClip.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
         this._filterMovieClip.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onError);
         this._filterMovieClip.load(new URLRequest(SystemConfig.FILTER_MOVIE_CLIP),new LoaderContext(true));
      }
      
      private function onComplete(param1:Event) : void {
      }
      
      private function onError(param1:Event = null) : void {
         if(this._filterMovieClip == null)
         {
            return;
         }
         this._filterMovieClip.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.onComplete);
         this._filterMovieClip.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,this.onError);
         this._filterMovieClip.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onError);
         this._filterMovieClip = null;
      }
      
      private function onCloseBtnClick(param1:MouseEvent = null) : void {
         this.close();
      }
      
      private function onTextEventClick(param1:TextEvent) : void {
         if(this._sexType == UserDef.USER_SEX_MALE)
         {
            dispatchEvent(new SettingEvent(SettingEvent.Evt_FilterTextLinkClick,this._isHavAtherData?UserDef.USER_SEX_FEMALE:UserDef.USER_SEX_NONE));
         }
         else if(this._sexType == UserDef.USER_SEX_FEMALE)
         {
            dispatchEvent(new SettingEvent(SettingEvent.Evt_FilterTextLinkClick,this._isHavAtherData?UserDef.USER_SEX_MALE:UserDef.USER_SEX_NONE));
         }
         else
         {
            dispatchEvent(new SettingEvent(SettingEvent.Evt_FilterTextLinkClick,UserDef.USER_SEX_NONE));
         }
         
         this.close();
      }
   }
}
